package com.bw.zg3.Car

import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.paging.DataSource
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil.ItemCallback
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.bw.base.entity.MessageEntityItem
import com.bw.zg3.R
import com.bw.zg3.databinding.MeBinding


class CarApter :PagingDataAdapter<MessageEntityItem,CarApter.CarviewHolder>(mess){
    companion object{
        val mess= object : ItemCallback<MessageEntityItem>() {
            override fun areItemsTheSame(
                oldItem: MessageEntityItem,
                newItem: MessageEntityItem,
            ): Boolean {
                return oldItem==newItem
            }

            override fun areContentsTheSame(
                oldItem: MessageEntityItem,
                newItem: MessageEntityItem,
            ): Boolean {
                return oldItem.id==newItem.id
            }

        }
    }
    class CarviewHolder(view: View):ViewHolder(view){
        val binding=DataBindingUtil.bind<MeBinding>(view)

    }
    override fun onBindViewHolder(holder: CarApter.CarviewHolder, position: Int) {
        holder.binding?.messag=getItem(position)
        if(getItem(position)?.messageStatus=="已读"){
            holder.binding?.uu?.setBackgroundColor(Color.BLUE)
            holder.binding?.imageView5?.setImageResource(R.drawable.img_15)
        }else if(getItem(position)?.messageStatus=="处理中"){
            holder.binding?.uu?.setBackgroundColor(Color.GREEN)
            holder.binding?.imageView5?.setImageResource(R.drawable.img_16)
        }else if(getItem(position)?.messageStatus=="已过期"){
            holder.binding?.uu?.setBackgroundColor(Color.GRAY)
            holder.binding?.imageView5?.setImageResource(R.drawable.img_14)
        }

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CarviewHolder {
        val from = LayoutInflater.from(parent.context).inflate(R.layout.me,parent,false)
        return CarviewHolder(from)
    }


}